package Boundary;

import javax.swing.JFrame;
import javax.swing.JLabel;
import java.awt.Font;
import javax.swing.JTextField;
import javax.swing.JButton;
import javax.swing.JTextArea;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;

import Controller.CreateEventController;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.JCheckBox;

/** create Event Form 
 * 
 * @author zhaolongli
 *
 */

public class CreateEventForm extends JFrame{
	
	// has reference to the main Frame
	MainGUI mainFrame;
	
	JTextField nField;
	JTextField mField;
	JButton btnCreate;	
	JButton btnCancel;
	JTextArea questionField;
	
	public CreateEventForm(MainGUI f){
		mainFrame = f;
		
		setResizable(false);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setTitle("DecisionLine Client");
		setBounds(200,100,300,400);
		
		JLabel lblOfUser = new JLabel("# of User");
		lblOfUser.setFont(new Font("Lucida Grande", Font.PLAIN, 12));
		
		nField = new JTextField();
		nField.setColumns(10);
		
		JLabel lblNewLabel = new JLabel("# of Rounds");
		lblNewLabel.setFont(new Font("Lucida Grande", Font.PLAIN, 12));
		
		mField = new JTextField();
		mField.setColumns(10);
		
		btnCreate = new JButton("Create");		
		btnCreate.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				new CreateEventController(CreateEventForm.this).process();
				
			}
		});
		btnCancel = new JButton("Cancel");
		btnCancel.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				CreateEventForm.this.setVisible(false);
				mainFrame.setVisible(true);
			}
		});
		
		JLabel lblQuestion = new JLabel("Question");
		lblQuestion.setFont(new Font("Lucida Grande", Font.PLAIN, 12));
		
		questionField = new JTextArea();
		questionField.setFont(new Font("Lucida Grande", Font.PLAIN, 11));
		questionField.setText("Please ignore these TextField and\nJust click \"Create\" for a quick test\n#of user and # of round are \nhardcoded for now\n");
		questionField.setLineWrap(true);
		
		JCheckBox chckbxOpenEvent = new JCheckBox("Open Event");
		
		GroupLayout groupLayout = new GroupLayout(getContentPane());
		groupLayout.setHorizontalGroup(
			groupLayout.createParallelGroup(Alignment.LEADING)
				.addGroup(groupLayout.createSequentialGroup()
					.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
						.addGroup(groupLayout.createSequentialGroup()
							.addGap(32)
							.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
								.addGroup(groupLayout.createSequentialGroup()
									.addComponent(lblOfUser, GroupLayout.PREFERRED_SIZE, 74, GroupLayout.PREFERRED_SIZE)
									.addGap(27)
									.addComponent(nField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
								.addGroup(groupLayout.createSequentialGroup()
									.addComponent(lblNewLabel)
									.addGap(31)
									.addComponent(mField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))))
						.addGroup(groupLayout.createSequentialGroup()
							.addGap(94)
							.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
								.addComponent(btnCancel, GroupLayout.PREFERRED_SIZE, 117, GroupLayout.PREFERRED_SIZE)
								.addComponent(btnCreate, GroupLayout.PREFERRED_SIZE, 117, GroupLayout.PREFERRED_SIZE)
								.addComponent(chckbxOpenEvent)))
						.addGroup(groupLayout.createSequentialGroup()
							.addGap(32)
							.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
								.addComponent(questionField, GroupLayout.PREFERRED_SIZE, 235, GroupLayout.PREFERRED_SIZE)
								.addComponent(lblQuestion, GroupLayout.PREFERRED_SIZE, 61, GroupLayout.PREFERRED_SIZE))))
					.addContainerGap(33, Short.MAX_VALUE))
		);
		groupLayout.setVerticalGroup(
			groupLayout.createParallelGroup(Alignment.LEADING)
				.addGroup(groupLayout.createSequentialGroup()
					.addGap(47)
					.addComponent(lblQuestion, GroupLayout.PREFERRED_SIZE, 16, GroupLayout.PREFERRED_SIZE)
					.addGap(12)
					.addComponent(questionField, GroupLayout.PREFERRED_SIZE, 57, GroupLayout.PREFERRED_SIZE)
					.addPreferredGap(ComponentPlacement.UNRELATED)
					.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
						.addComponent(nField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
						.addComponent(lblOfUser, GroupLayout.PREFERRED_SIZE, 16, GroupLayout.PREFERRED_SIZE))
					.addGap(2)
					.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
						.addComponent(mField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
						.addComponent(lblNewLabel, GroupLayout.PREFERRED_SIZE, 16, GroupLayout.PREFERRED_SIZE))
					.addPreferredGap(ComponentPlacement.UNRELATED)
					.addComponent(chckbxOpenEvent)
					.addGap(18)
					.addComponent(btnCreate)
					.addPreferredGap(ComponentPlacement.RELATED)
					.addComponent(btnCancel)
					.addGap(59))
		);
		getContentPane().setLayout(groupLayout);
		
		
		
	}
	
	/** get main GUI */
	public MainGUI getMain(){
		return mainFrame;
	}
	
}
